/**
 * 命名管道写端
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <unistd.h>

int main(int argc, char **argv)
{
    if (2 > argc)
    {
        fprintf(stderr, "%s <fifo_filename>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    if (mkfifo(argv[1], 0664) < 0)
    {
        perror("mkfifo error: ");
        exit(EXIT_FAILURE);
    }

    int fd = open(argv[1], O_WRONLY);
    if (0 > fd)
    {
        perror("open error: ");
        exit(EXIT_FAILURE);
    }
    char *str = "Hello World!";
    write(fd, str, strlen(str));

    close(fd);
    return 0;
}